import { UserConfigExport, ConfigEnv } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import viteSvgIcons from 'vite-plugin-svg-icons'
import path from 'path'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default ({ command }: ConfigEnv): UserConfigExport => {
  const prodMock = true
  return {
    base: '/',
    publicDir: 'public',
    // base: command === 'serve' ? '/' : '/vue3-element-admin-ts/',
    plugins: [
      vue(),
      viteSvgIcons({
        // 配置路径在你的publish里的svg存放文件
        iconDirs: [path.resolve(process.cwd(), 'public/svgIcons')],
        symbolId: 'icon-[dir]-[name]'
      }),
      AutoImport({
        resolvers: [ElementPlusResolver()],
        imports: ['vue']
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
      VueSetupExtend()
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src'),
        '#': path.resolve(__dirname, 'types')
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "./src/styles/variables.scss";`
        }
      }
    },
    server: {
      host: '0.0.0.0',
      port: 3000,
      open: true
    },
    // server: {
    //   port: 3002,
    //   open: false,
    //   proxy: {
    //     '/api': {
    //       target: 'http://admin.xueyueob.cn/api',
    //       changeOrigin: true,
    //       ws: true,
    //       rewrite: (path) => path.replace(new RegExp('^/api'), '')
    //     }
    //   }
    // },
    build: {
      // sourcemap: true,
      manifest: true,
      rollupOptions: {
        output: {
          manualChunks: {
            vue: ['vue', 'vue-router', 'vuex'],
            'element-plus': ['element-plus'],
            echarts: ['echarts'],
            xlsx: ['xlsx'],
            'icons-vue': ['@element-plus/icons-vue']
          }
        }
      },
      chunkSizeWarningLimit: 500,
      outDir: './dist/motolive.58moto.com'
    }
  }
}
